# coding: utf-8

# Copyright (c) 2020-2023 Huawei Technologies Co., Ltd.
# oec-hardware is licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#     http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.
# Author: @quanren
# Create: 2023-01-10
# Desc: aiacc test, support Corerain series aiacc

import argparse
from hwcompatible.command import Command
from hwcompatible.test import Test
from cr_aiacc import CRAIaccTest


class aiaccTest(Test):
    def __init__(self):
        Test.__init__(self)
        self.requirements = ["gcc-c++", "make", "git"]
        self.device = None

    def setup(self, args=None):
        """
        Initialization before test
        """
        super().setup(args)
        self.device = getattr(args, 'device', None)
    
    def test(self):
        """
        Test case
        Returns:
            bool: Execution result
        """
        result = False
        driver = self.device.get_driver()
        if driver == "Corerain DMA":
            cr_test = CRAIaccTest(self.device, self.logger, self.command)
            cr_test.get_driver_info()
            result = cr_test.test_cr_aiacc_sample()
            return result 
        else:
            self.logger.info("No driver named Corerain DMA was found ! ", terminal_print=True)
            return result
            
        
